import Taro from "@tarojs/taro";

const baseURL = "---=";

export const request = (options: Request.Options) => {
  // ...
  const { method = "GET", path = "", data = {}, header = {} } = options;

  return new Promise((resolve, reject) => {
    Taro.request({
      method,
      url: baseURL + path,
      data,
      header: {
        "content-type": "application/json", // 默认值
        ...header,
      },
      success: (res) => {
        console.log("服务器数据：", res.data); // 保存服务器数据
        resolve(res.data);
      },
      fail: (err) => {
        console.log("错误信息：", err);
        reject(false);
      },
    });
  });
};
